package com.kkb.kkbportal.controller;

import com.kkb.kkbcommon.api.CommonResult;
import com.kkb.kkbportal.domain.ProductionInfo;
import com.kkb.kkbportal.service.ProductionInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName ProjectRegisterController
 * @Description 作品集
 * @Author mzj
 * @Date 2021/8/13
 **/
@RestController
@Api(tags = "作品集API", description = "作品集上传、展示、根据id查询、删除、编辑、分享")
@RequestMapping("production")
public class ProductionInfoController {
    @Resource
    private ProductionInfoService service;

    /**
     * 作品集上传 @Validated 做数据校验
     *
     * @param productionInfo
     * @return CommonResult
     */
    @ApiOperation(value = "作品集上传")
    @PostMapping("/production")
    public CommonResult insert(@RequestBody @Validated ProductionInfo productionInfo) {
        service.insert(productionInfo);
        return CommonResult.success(null);
    }


    /**
     * 作品集展示 @Validated 做数据校验
     *
     * @param condition 查询条件
     * @return 结果集
     */
    @ApiOperation(value = "作品集展示", notes = "作品集列表展示")
    @GetMapping("/produtions")
    public CommonResult<List<ProductionInfo>> findPage(@RequestBody @Validated ProductionInfo condition) {
        List<ProductionInfo> list = service.findPage(condition);
        return CommonResult.success(list);
    }

    /**
     * 作品集回显
     *
     * @param id 作品集id
     * @return CommonResult<ProductionInfo>
     */
    @ApiOperation(value = "作品集回显", notes = "根据作品集id查询作品集回显到修改页面")
    @GetMapping("/prodution/{id}")
    public CommonResult<ProductionInfo> findById(@PathVariable("id") @Validated Long id) {
        ProductionInfo productionInfo = service.selectById(id);
        return CommonResult.success(productionInfo);
    }

    /**
     * 作品集删除 @Validated 做数据校验
     *
     * @param id 作品集id
     * @return CommonResult
     */
    @ApiOperation(value = "作品集删除", notes = "根据id删除作品集")
    @DeleteMapping("/production/{id}")
    public CommonResult delete(@PathVariable("id") @Validated Long id) {
        service.delete(id);
        return CommonResult.success(null);
    }

    /**
     * 更新作品集
     *
     * @param productionInfo 作品集对象
     * @return CommonResult
     */
    @ApiOperation(value = "作品集更新", notes = "根据id更新作品集")
    @PutMapping("/production")
    public CommonResult update(@RequestBody @Validated ProductionInfo productionInfo) {
        service.update(productionInfo);
        return CommonResult.success(null);
    }
}
